package cn.zhouyafeng;

import cn.zhouyafeng.itchat4j.TulingRobot;
import cn.zhouyafeng.itchat4j.Wechat;
import cn.zhouyafeng.shares.ShareObj;
import cn.zhouyafeng.shares.ShareResult;
import org.apache.commons.lang3.StringUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Main
{
    static Wechat wechat;
    static WatherMain watherMain = new WatherMain();
    static ShareObj obj = new ShareObj("600016", "");
    static int num = 1;

    public static void main(String[] args) {
        TulingRobot msgHandler = new TulingRobot();
//        msgHandler.watherMain = watherMain;
        wechat = new Wechat(msgHandler, args[0]);
        wechat.start();
        run();
    }


    public static void run () {

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MINUTE, 50);
//        calendar.set(Calendar.SECOND, 1);
        Date defaultdate = calendar.getTime();
        Timer dTimer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
//                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
//                if (hour < 9 || hour > 22) {
//                    return;
//                }
                ShareResult price = obj.getPrice();
                if (StringUtils.isNotBlank(price.msg)) {
                    wechat.sendId(price.msg);
                    return;
                }
                double val = price.price;
                if (num++ <= 10) {
                    wechat.sendId(val + "");
                }
                if (val > 6.1) {
                    wechat.sendId(val + "");
                }
            }
        };

        dTimer.schedule(timerTask, defaultdate , 10 * 1000L);//24* 60* 60 * 1000
    }


}
